<template>
  <div class="app-container add">
    <h4>基础信息</h4>
    <table  class="table"  border="1" rules="all">
      <tr>
        <td>设备名称</td>
        <td colspan="3" @click="selectEquipment"><span class="cont" v-if="addForm.devicename">{{addForm.devicename}}({{addForm.devicecoder}})</span></td>
      </tr>
      <tr>
        <td>开始时间</td>
        <td>
          <el-date-picker
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            v-model="addForm.startdate">
          </el-date-picker>
        </td>
        <td>结束时间</td>
        <td>
          <el-date-picker
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            v-model="addForm.enddate">
          </el-date-picker>
        </td>
      </tr>
      <tr>
        <td>计划名称</td>
        <td><el-input placeholder="请填写" v-model="addForm.planname"></el-input></td>
        <td>责任人</td>
        <td>
          <el-select  placeholder="请选择" clearable v-model="addForm.chargeuser">
            <el-option
              v-for="item in userList"
              :key="item.userId"
              :label="item.nickName"
              :value="item.userId"
            />
          </el-select>
        </td>
      </tr>
      <tr>
        <td>养护类型</td>
        <td>
          <el-select  placeholder="请选择" clearable v-model="addForm.conservetype">
            <el-option
              v-for="item in maintainType"
              :key="item.dictCode"
              :label="item.dictLabel"
              :value="item.dictCode"
            />
          </el-select>
        </td>
        <td>养护周期</td>
        <td class="short">
          <el-input placeholder="请填写" v-model="addForm.circlecycle"></el-input>
          <el-select  placeholder="请选择" clearable  v-model="addForm.circleunit">
            <el-option
              v-for="item in [{name:'天',value: '1'},{name: '周',value: '2'},{name: '月',value: '3'}]"
              :key="item.value" :label="item.name"  :value="item.value"/>
          </el-select>
        </td>
      </tr>
      <tr>
        <td>有效时间</td>
        <td class="short">
          <el-input placeholder="请填写" v-model="addForm.validtime"></el-input>
          <el-select  placeholder="请选择" clearable  v-model="addForm.validtimeunit">
            <el-option
              v-for="item in [{name:'天',value: '1'},{name: '周',value: '2'},{name: '月',value: '3'}]"
              :key="item.value" :label="item.name"  :value="item.value"/>
          </el-select>
        </td>
        <td>启用养护计划</td>
        <td>
          <el-select  placeholder="请选择" clearable  v-model="addForm.isstart">
            <el-option
              v-for="item in [{label: '是',value:'1'},{label: '否',value:'0'}]"
              :key="item.value" :label="item.label"  :value="item.value"/>
          </el-select>
        </td>
      </tr>
      <tr>
        <el-tooltip class="item" effect="dark" content="如果当前时间段未设置人员则分派给计划责任人" placement="bottom-start">
        <td>是否关联班组<span class="red"><i class="el-icon-warning-outline" /></span></td>
        </el-tooltip>
        <td>
          <el-select  placeholder="请选择" clearable  v-model="addForm.teamId">
            <el-option
              v-for="item in [{label: '是',value:'1'},{label: '否',value:'0'}]"
              :key="item.value" :label="item.label"  :value="item.value"/>
          </el-select>
        </td>
        <td>提前提醒时间</td>
        <td class="short">
          <el-input placeholder="请填写" v-model="addForm.noticecycle"></el-input>
          <el-select  placeholder="请选择" clearable  v-model="addForm.noticeunit">
            <el-option
              v-for="item in [{name:'天',value: '1'},{name: '周',value: '2'},{name: '月',value: '3'}]"
              :key="item.value" :label="item.name"  :value="item.value"/>
          </el-select>
        </td>
      </tr>
      <tr>
        <td>养护说明</td>
        <td colspan="3">
          <el-input placeholder="请填写" type="textarea" :rows="4" v-model="addForm.conserveexplain"></el-input>
        </td>
      </tr>
    </table>

    <div class="btn">
      <el-button size="mini" type="primary" @click="submit">提交</el-button>
    </div>
    <addDialog v-if="selectDialog" @selectChange="currentChange" @chooseInfo="chooseInfo"></addDialog>
  </div>
</template>

<script>
  import addDialog from '@/views/conserve/conservePlan/conservePlanAddDialog'
  import {conserveplanAdd,conserveplanEdit,conserveplanInfo,feiyong,conserveType} from '@/api/curing/index'
  import {listUser} from '@/api/inventory/index'
    export default {
      name: "add.vue",
      components:{
        addDialog,
      },
      data(){
          return{
            fileList:[],
            addForm: {
              isstart:'1'
            },//查询条件
            selectDialog:false,
            selectData:'',
            userList:[],
            //养护类型
            maintainType:[],
          }
      },
      created() {
        this.getUser()
        this.getconserveType()
          if(this.$route.query.id){
            conserveplanInfo(this.$route.query.id).then((res)=>{
              if(res.code==200){
                this.addForm=res.data
              }
            })
          }
      },
      methods:{
        getUser(){
          listUser().then((res)=>{
            if(res.code==200){
              this.userList=res.rows
            }
          })
        },
        getconserveType(){
          conserveType().then((res)=>{
            this.maintainType=res.data
          })
        },
        feiyong(){
          feiyong().then((res)=>{
            if(res.code==200){
              this.userList=res.rows
            }
          })
        },
        chooseInfo(info){
          this.addForm.devicename=info.deviceName
          this.addForm.devicecoder=info.deviceCode
          this.addForm.deviceId=info.id
          this.selectDialog=false
        },
        submit(){
          if(this.$route.query.id){
            //修改
            conserveplanEdit(this.addForm).then((res)=>{
              if(res.code==200){
                this.$message.success(res.msg)
                this.$router.push({path:'/conserve/conservePlan'});
              }
            })
          }else{
            //提交
            conserveplanAdd(this.addForm).then((res)=>{
              if(res.code==200){
                this.$message.success(res.msg)
                this.$router.push({path:'/conserve/conservePlan'});
              }
            })
          }
          
        },
        //选择设备
        selectEquipment(){
          this.selectDialog=true
        },
        //成功回调
        currentChange(data){
          if(data){
            this.selectData=data
          }
          this.selectDialog=false
        }
      }
    }
</script>

<style  lang="scss">
.add{
  h4{
    color: #05A380;
  }
  .btn{
    width:900px;
    text-align: center;
    margin-top:30px;
  }
  .table{
    margin-left: 15px;
    border: 1px solid #cccccc;
    color: #606266;
    font-size: inherit;
    .el-input--medium .el-input__inner,.el-textarea .el-textarea__inner{
      border: none;
    }
    tr{
      td:nth-child(2n-1){
        width: 150px;
        text-align: center;
      }
      td{
        width:300px;
        line-height: 35px;
        .red{
          padding:0 3px;
          color:red;
        }
        .el-select{
          width:100%;
        }
        .cont{
          padding-left:10px;
        }
      }
      .short{
        .el-input{
          width:60%;
        }
        .el-select{
          width:40%;
          .el-input{
            width: 100%;
          }
        }
      }
    }
  }

}
</style>
